<template>
	<view class="userset">
		<view class="modification">
			<view class="modmoble" @click="modmoble">
				<view class="modlist">
					<text class="iconfont icon-shouji"></text>
					<text class="modmovi">修改手机号</text>
				</view>
				<text class="iconfont icon-arrow-right"></text>
			</view>
			<text class="bef"></text>
			<view class="modpass" @click="modpass">
				<view class="modlist">
					<text class="iconfont icon-jiesuo"></text>
					<text class="modmovi">修改密码</text>
				</view>
				<text class="iconfont icon-arrow-right"></text>
			</view>
		</view>
		<view class="edition">
			<view class="modmoble" @click="clearStorage">
				<view class="modlist">
					<text class="iconfont icon-yunongtongqingchuhuancun"></text>
					<text class="modmovi">清除缓存</text>
				</view>
				<view>
					<text class="si">{{ storageSize }}</text>
					<text class="iconfont icon-arrow-right"></text>
				</view>
			</view>
			<text class="bef"></text>
			<view class="modpass">
				<view class="modlist">
					<text class="iconfont icon-banben"></text>
					<text class="modmovi">当前版本</text>
				</view>
				<view>
					<text class="si">1.0.0</text>
					<text class="iconfont icon-arrow-right"></text>
				</view>
			</view>
		</view>
		<view class="quit"><button type="default" class="btn" @click="quit">退出当前账号</button></view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			storageSize: ''
		};
	},
	onLoad() {
		this.getStorageSize();
	},
	methods: {
		quit() {
			uni.showModal({
				title: '提示',
				content: '确定要退出账号吗?',
				success: function(res) {
					if (res.confirm) {
						uni.reLaunch({
							url: '../login/login'
						});
					} else if (res.cancel) {
						console.log('用户点击取消');
					}
				}
			});
		},
		modmoble() {
			uni.navigateTo({
				url: '../changeMobileByCode/index'
			});
		},
		modpass() {
			uni.navigateTo({
				url: '../my/changePass'
			});
		},

		getStorageSize: function() {
			let that = this;
			uni.getStorageInfo({
				success(res) {
					console.log(res.keys);
					//console.log(res.limitSize);
					let size = res.currentSize;
					if (size < 1024) {
						that.storageSize = size + ' B';
					} else if (size / 1024 >= 1 && size / 1024 / 1024 < 1) {
						that.storageSize = Math.floor((size / 1024) * 100) / 100 + ' KB';
					} else if (size / 1024 / 1024 >= 1) {
						that.storageSize = Math.floor((size / 1024 / 1024) * 100) / 100 + ' M';
					}
				}
			});
		},
		clearStorage: function() {
			let that = this;
			uni.showModal({
				title: '提示',
				content: '确定清除缓存吗?',
				confirmText: '立即清除',
				success(res) {
					if (res.confirm) {
						uni.clearStorageSync();
						//重新获取并显示清除后的缓存大小
						that.getStorageSize();
						uni.showToast({
							title: '清除成功'
						});
					}
				}
			});
		},
		// UpVersions() {
		// 	var _this = this;
		// 	uni.request({
		// 		url: `${this.$store.state.apiBaseUrl}/users/versions`, //请求接口
		// 		method: 'POST',
		// 		success: result => {
		// 			if (result.data.code == 1) {
		// 				plus.runtime.getProperty(plus.runtime.appid, function(inf) {
		// 					if (inf.version != result.data.data.versions) {
		// 						uni.showModal({
		// 							title: '发现新版本',
		// 							content: '确认下载更新',
		// 	 					success: res => {
		// 								if (res.confirm == true) {
		// 									//当用户确定更新，执行更新
		// 									_this.doUpData();
		// 								}
		// 							}
		// 						});
		// 					}

		// 			});
		// 			}
		// 		}
		// 	});
		// }
	}
};
</script>

<style lang="less">
@import url('../../static/style/userSet.less');
</style>
